//
//  Omron.h
//  OmronFramework
//
//  Created by Paul Hubbard on 6/19/08.
//  Copyright 2008 SDSC. All rights reserved.
//

#import <Cocoa/Cocoa.h>

#include <stdio.h>
#include <IOKit/IOCFPlugIn.h>
#include <IOKit/hid/IOHIDKeys.h>
#include <CoreFoundation/CoreFoundation.h>

#include <sys/cdefs.h>
#include <CoreFoundation/CoreFoundation.h>
#include <CoreFoundation/CFPlugInCOM.h>
#include <IOKit/IOTypes.h>
#include <IOKit/IOReturn.h>
#include <IOKit/hid/IOHIDKeys.h>

//! @note this is required for example - Interface122 is obsolete it seems. Deprecated?
#include <IOKit/hid/IOHIDLibObsolete.h>

// Structure for USB report from device - buffer may be wrong size!
typedef struct  
    {
        io_object_t             ioObject;
        IOHIDDeviceInterface122 **interface;
        int                     gotdata;
        unsigned char           buffer[64];
    }reader_t;

// States we can be in...half-assed state machine
typedef enum {STATE_NONE, STATE_SEARCHING, STATE_FOUND, STATE_IDLE, STATE_RXTX, STATE_ERR} state_t;

@interface OmronUSB : NSObject {
    
    // Internal variables/structs
    SInt32              score;
    IOCFPlugInInterface **plugInInterface;
    CFRunLoopSourceRef  eventSource;
    mach_port_t         port;
    state_t             state;
    io_object_t         hidDevice;
    reader_t            *reader;
    IOReturn reason;
    BOOL                debugging;
}

// Bus iterator, returns true for found
- (BOOL) detect;

// Hack-ish code to dump buffer to stdout
- (void) dumpBuffer;

// Data downloader
- (NSMutableData *) getReport:(const int)reportId;

// Set/clear boolean
- (void) debugOn;
- (void) debugOff;

@end
